Keep postRequest primary-chat only#508
Conversation
Route subagent completions exclusively through subagentPostRequest so post-request hooks do not emit duplicate notifications for subagent turns. Update the hook docs, changelog, and lifecycle tests to match the contract. 🤖 Generated with [ECA](https://eca.dev) (openai/gpt-5.5 - high) Co-Authored-By: eca-agent <git@eca.dev>
|
CI failure is pre-existing and unrelated to this PR The Root cause: Fix: swap the order in (defn kill-job! [job-id]
(if-let [job (get-job job-id)]
(if (= :running (:status job))
(do
;; Commit :killed status before destroying the process so that
;; monitor-process-exit! never overwrites it with :failed (exit 143).
(swap! registry* (fn [reg]
(-> reg
(assoc-in [:jobs job-id :status] :killed)
(assoc-in [:jobs job-id :ended-at] (Instant/now)))))
(kill-job-impl job)
(logger/info logger-tag "Killed background job" {:id job-id})
true)
...)))The existing unit test |
|
c/c @zikajk |
|
@itkonen @ericdallo |
|
Great this resolved! I already started orchestrating a fix around your earlier idea around |
|
@itkonen I was wrong, because Claude Code allows you to specify hooks within subagents frontmatter, and when you define a Stop hook there, it automatically changes to a subagentStop hook. But in all other cases (hooks in the global / project config), the Stop and subagentStop hooks are separate :-) |
Issue #505 still remains after the previous fix. The remaining problem is that the
postRequesthook is still fired by subagents, which can still cause duplicate or misleading post-request notifications.This PR limits
postRequestexclusively to main/primary-agent chats, and makessubagentPostRequestthe exclusive post-request hook for subagent chats.AI summary
This change separates post-request hook dispatch by chat type:
postRequestnow runs only after primary-agent prompts.subagentPostRequestnow runs only after subagent prompts.parent_chat_id.continue: false,followUp,systemMessage, and exit-2 follow-up behavior continue to work for the selected post-request hook type.The lifecycle tests, hook documentation, and changelog have been updated to match the new contract.
Refs #505.
Testing
clojure -M:test --focus eca.features.hooks-testLC_ALL=C bb testclj-kondo --lint src/eca/features/chat/lifecycle.clj test/eca/features/hooks_test.cljChecklist